package com.infotel.chat;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlIDREF;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.XmlValue;

@XmlType(propOrder = { "author", "date", "content"})
@XmlAccessorType(XmlAccessType.PROPERTY)
public class Messages{
  
    private Users author;
    
    @XmlAttribute(required = true)
    @XmlIDREF
    public Users getAuthor() {
        return author;
    }

    public void setAuthor(Users author) {
        this.author = author;
    }

    private Date date;
    private String content;

    public Messages(String author, Date date, String content) {
        this.author.setId(author);
        this.date = date;
        this.content = content;
    }
    
    public Messages(Users author, Date date, String content) {
        this.author = author;
        this.date = date;
        this.content = content;
    }

    public Messages() {
        this.author = null;
        this.date = null;
        this.content = null;
    }

    @XmlTransient
    public String getAuteur() {
        return author.getId();
    }

    public void setAuteur(String author) {
        this.author.setId(author);
    }

    @XmlAttribute(required = true)
    public String getDate() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
        return sdf.format(date);
    }

    public void setDate(Date date) {
        this.date = date;
    }

    @XmlValue
    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String toString() {

        return this.author.getId() + " " + this.date + " " + this.content;
    }

}
